home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-23 | 1.9 KB | 105 lines | [TEXT/CWIE] |
- unit MyGrowZones;
-
- interface
-
- uses
- Types;
-
- procedure StartupGrowZones;
- procedure ConfigureGrowZones(size: longint; alertid: integer);
- function MemoryCritical: boolean;
- function EnoughSpace (total, contig: longint): boolean;
-
- implementation
-
- {$IFC undefined GrowZoneAlerts}
- {$SETC GrowZoneAlerts := 1}
- {$ENDC}
-
- uses
- Memory, OSUtils,
- {$IFC GrowZoneAlerts}
- MyCleverAlerts,
- {$ENDC}
- PreserveA5, MyCallProc, MyStartup;
-
- var
- gzh: handle;
- gz_size: longINt;
- lastgzh: handle;
- id: integer;
-
- function MyGrowZone (size: longint): longint;
- var
- saved_A5:Ptr;
- begin
- size:=size; { UNUSED! }
- saved_A5 := SetPreservedA5;
- if gzh <> nil then begin
- MyGrowZone := GetHandleSize(gzh);
- DisposeHandle(gzh);
- gzh := nil;
- end
- else begin
- MyGrowZone := 0;
- end;
- RestoreA5(saved_A5);
- end;
-
- function MemoryCritical: boolean;
- begin
- MemoryCritical := gzh = nil;
- end;
-
- function EnoughSpace (total, contig: longint): boolean;
- var
- t, c: longint;
- begin
- PurgeSpace(t, c);
- EnoughSpace := not MemoryCritical & (t >= total) & (c >= contig);
- end;
-
- procedure IdleGrowZone;
- begin
- if gzh = nil then begin
- gzh := NewHandle(gz_size);
- {$IFC GrowZoneAlerts}
- if (gzh = nil) and (lastgzh <> nil) and (id > 0) then begin
- CleverNotifyAlert(id);
- end;
- {$ENDC}
- lastgzh := gzh;
- end;
- end;
-
- procedure ConfigureGrowZones(size: longint; alertid: integer);
- begin
- gz_size := size;
- id := alertid;
- end;
-
- function InitGrowZone(var msg: integer): OSStatus;
- begin
- msg := msg; { Unused }
- SetGrowZone(NewProc(@MyGrowZone,uppPascal44ProcInfo));
- gzh := nil;
- lastgzh := nil;
- IdleGrowZone;
- InitGrowZone := noErr;
- end;
-
- procedure FinishGrowZone;
- begin
- if gzh <> nil then begin
- DisposeHandle(gzh);
- gzh := nil;
- end;
- end;
-
- procedure StartupGrowZones;
- begin
- StartupPreserveA5;
- SetStartup(InitGrowZone, IdleGrowZone, 30, FinishGrowZone);
- end;
-
- end.